package org.example.bio.ch1;


import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class Client {

    public static void main(String[] args) {

        try {
            Socket socket = new Socket("127.0.0.1", 8000);

            while (true){
                String msg = "hello world";
                socket.getOutputStream().write(msg.getBytes());
                System.out.println("发送数据");
                InputStream inputStream = socket.getInputStream();
                int len;
                byte[] data = new byte[1024];
                len = inputStream.read(data);
                String message = new String(data, 0, len);
                System.out.println(message);
                Thread.sleep(5000);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
